//
//  API.swift
//  GHMoyaNetWorkTest
//
//  Created by Guanghui Liao on 3/30/18.
//  Copyright © 2018 liaoworking. All rights reserved.
//https://github.com/Moya/Moya/blob/master/docs_CN/Examples/Basic.md

import Foundation
import Moya

enum API1{
    ///获取酒店城市信息
    case getCityCode
    ///获取酒店列表
    case searchHotelList(parameters:[String:Any])
    ///获取酒店详情列表
    case searchHotelDetail(parameters:[String:Any])
    ///根据城市ID获取筛选酒店条件信息
    case searchHotelAllMsg(parameters:[String:Any])
    ///获取图片列表
    case searchHotelImageList(parameters:[String:Any])
    ///获取房型图片列表
    case searchHotelRoomImage(parameters:[String:Any])
    ///批量获取房型图片
    case searchRoomImagesV2(parameters:[String:Any])
    ///获取酒店价格信息
    case searchHotelPrice(parameters:[String:Any])
    ///酒店预下单
    case hotelAvail(parameters:[String:Any])
    ///根据城市ID查询机场火车站信息
    case searchTrainAndAirportByCityId(parameters:[String:Any])
    ///酒店列表筛选条件信息
    case searchHotelCondition(parameters:[String:Any])
    ///根据城市筛选地铁信息
    case searchSubwayInfomation(parameters:[String:Any])
    ///酒店下单
    case createHotelOrder(parameters:[String:Any])
    ///酒店支付
    case orderPay(parameters:[String:Any])
    ///根据城市名称获取城市id接口
    case getCityIdByName(parameters:[String:Any])
    ///获取酒店筛选条件
    case getHotelCondition(parameters:[String:Any])
    ///评论列表
    case getCommentList(parameters:[String:Any])
    ///评论
    case hoteevaluate(parameters:[String:Any])
    
    ///获取所有车站信息接口
    case getStationData
    ///查询站站车次列表接口
    case searchTrainsBetweenStations(parameters:[String:Any])
    ///获取车次经停站接口
    case getStopStations(parameters:[String:Any])
    ///12306账号登录接口
    case apply12306Login(parameters:[String:Any])
    ///获取12306登录状态接口
    case get12306LoginStatus(parameters:[String:Any])
    ///12306账号短信核验
    case smsVerify12306Account(parameters:[String:Any])
    ///火车票下单接口
    case createOrder(parameters:[String:Any])
    ///订单取消接口
    case orderCancel(parameters:[String:Any])
    ///退票申请接口
    case orderRefund(parameters:[String:Any])
    ///改签申请接口
    case orderChangeQuery(parameters:[String:Any])
    ///用户火车票订单列表
    case getOrderList(parameters:[String:Any])
    
    ///获取用户身份证信息
    case gitIdCardList
    ///新增用户身份证信息
    case addUserIdCard(parameters:[String:Any])
    ///身份证修改
    case updateUserIdCard(parameters:[String:Any])
    ///删除指定的身份证
    case delUserIdCard(parameters:[String:Any])
    ///改签支付接口地址
    case orderChangePay(parameters:[String:Any])
    ///手机验证码登录
    case mobilelogin(parameters:[String:Any])
    
    case railwaysOrderPay(parameters:[String:Any])
    
    
    //*****************************门票**********************************
    
    ///获取门票城市信息
    case tgetCityCode
    
     /// 获取门票景点筛选条件
    case getScenicSpotCondition
    
    ///获取门票景点列表接口
    case getScenicSpotList(parameters:[String:Any])
    
    ///获取门票详情列表接口
    case getScenicSpotDetail(parameters:[String:Any])
    
    /// 获取景点门票资源详情
    
    case getResourceDetail(parameters:[String:Any])
    
    ///门票动态表单
    case orderDynamicTemplate(parameters:[String:Any])
    
    ///获取门票价格日历
    case getResourcePriceCalendar(parameters:[String:Any])
    
    ///门票可订检查
    case orderCanBooking(parameters:[String:Any])
    
    /// 门票下单接口
    case tcreateOrder(parameters:[String:Any])
    
    ///门票支付接口地址
    case torderPay(parameters:[String:Any])
    
    /// 用户门票订单列表
    case tgetOrderList(parameters:[String:Any])
    
    /// 获取资讯列表信息
    case serviceGetNews
    
    case serviceGetNewsById(parameters:[String:Any])
    
    
    
    //*********************************首页
    //添加接送机信息
    case addAirportTransfer(parameters:[String:Any])
    
    //添加接道路救援信息
    case addRoadRescue(parameters:[String:Any])
    
    //添加租车信息
    case addCarRental(parameters:[String:Any])
    
    
    //获取机票订单
    case getFlightOrderList(parameters:[String:Any])
    
    //获取酒店订单
    case getHotelOrderList(parameters:[String:Any])
    
    //获取火车票订单
    case getRailwayOrderList(parameters:[String:Any])
    
    //我的订单
    case getMyOrder(parameters:[String:Any])
        
    //积分订单
    case getBonusOrder(parameters:[String:Any])
    
    case getPickupList//接送机订单
    
    case getRescueList//道路救援
    
    case getRentCarList//租车
    
    //意见反馈
    case feedBack(parameters:[String:Any])
    
    //联系我们
    case contactUS
    
    //我的地址
    case getMyAddress
    
    //常用信息
    case getCommenInfo
    
    //积分信息
    case getMyIntegralInfo
}

extension API1:TargetType{
    var baseURL: URL {

        return URL.init(string:(Moya_baseURL))!
    }
    
    var path: String {
        switch self {
        case .getCityCode:
            return "hotel/getCityCode"
        ///搜索商品接口
        case .searchHotelList:
            return "hotel/searchHotelList"
        case .searchHotelDetail:
            return "hotel/searchHotelDetail"
        case .searchHotelAllMsg:
            return "hotel/searchHotelAllMsg"
        case .searchHotelImageList:
            return "hotel/searchHotelImageList"
        case .searchHotelRoomImage:
            return "hotel/searchHotelRoomImage"
        case .searchRoomImagesV2:
            return "hotel/searchRoomImagesV2"
        case .searchHotelPrice:
            return "hotel/searchHotelPrice"
        case .hotelAvail:
            return "hotel/hotelAvail"
        case .searchTrainAndAirportByCityId:
            return "hotel/searchTrainAndAirportByCityId"
        case .searchHotelCondition:
            return "hotel/searchHotelCondition"
        case .searchSubwayInfomation:
            return "hotel/searchSubwayInfomation"
        case .createHotelOrder:
            return "hotel/createHotelOrder"
        case .orderPay:
            return "hotel/orderPay"
        case .getCityIdByName:
            return "hotel/getCityIdByName"
        case .getHotelCondition:
            return "hotel/getHotelCondition"
            
        ///获取所有车站信息接口
        case .getStationData:
            return "railways/getStationData"
        ///查询站站车次列表接口
        case .searchTrainsBetweenStations:
            return "railways/searchTrainsBetweenStations"
        ///获取车次经停站接口
        case .getStopStations:
            return "railways/getStopStations"
        ///12306账号登录接口
        case .apply12306Login:
            return "railways/apply12306Login"
        ///获取12306登录状态接口
        case .get12306LoginStatus:
            return "railways/get12306LoginStatus"
        ///12306账号短信核验
        case .smsVerify12306Account:
            return "railways/smsVerify12306Account"
        ///火车票下单接口
        case .createOrder:
            return "railways/createOrder"
        ///订单取消接口
        case .orderCancel:
            return "railways/orderCancel"
        ///退票申请接口
        case .orderRefund:
            return "railways/orderRefund"
        ///改签申请接口
        case .orderChangeQuery:
            return "railways/orderChangeQuery"
            
        ///获取用户身份证信息
        case .gitIdCardList:
            return "user/gitIdCardList"
        ///新增用户身份证信息
        case .addUserIdCard:
            return "user/addUserIdCard"
        ///身份证修改
        case .updateUserIdCard:
            return "user/updateUserIdCard"
        ///删除指定的身份证
        case .delUserIdCard:
            return "user/delUserIdCard"
        case .getOrderList:
            return "railways/getOrderList"
        case .orderChangePay:
            return "railways/orderChangePay"
        ///手机验证码登录
        case .mobilelogin:
            return "user/mobilelogin"
        case .getScenicSpotCondition:
            return "ticket/getScenicSpotCondition"
        case .getScenicSpotList:
            return "ticket/getScenicSpotList"
        case .getScenicSpotDetail:
            return "ticket/getScenicSpotDetail"
        case .getResourceDetail:
            return "ticket/getResourceDetail"
        case .orderDynamicTemplate:
            return "ticket/orderDynamicTemplate"
        case .getResourcePriceCalendar:
            return "ticket/getResourcePriceCalendar"
        case .orderCanBooking:
            return "ticket/orderCanBooking"
        case .tcreateOrder:
            return "ticket/createOrder"
        case .torderPay:
            return "ticket/orderPay"
        case .tgetOrderList:
            return "ticket/getOrderList"
        case .tgetCityCode:
            return "ticket/getCityCode"
        case .railwaysOrderPay(_):
            return "railways/orderPay"
        case .getCommentList(_):
            return "orders/getCommentList"
        case .hoteevaluate(_):
            return "orders/hoteevaluate"
        case .serviceGetNews:
            return "service/getNews"
        case .serviceGetNewsById:
            return "service/getNewsById"
        case .addAirportTransfer(_):
            return "service/addAirportTransfer"
        case .addRoadRescue(_):
            return "service/addRoadRescue"
        case .addCarRental(_):
            return "service/addCarRental"
        case .getFlightOrderList:
            return "flight/getOrderList"
        case .getRailwayOrderList:
            return "railways/getOrderList"
        case .getHotelOrderList:
            return "hotel/getOrderList"
        case .getMyOrder:
            return "user/getOrderList"
        case .getBonusOrder:
            return "user/intergralOrder"
        case .getPickupList:
            return "service/getAirportTransferList"
        case .getRescueList:
            return "service/getRoadRescueList"
        case .getRentCarList:
            return "service/getCarRentalList"
        case .feedBack:
            return "user/complaint"
        //联系我们
        case .contactUS:
            return "user/contactUs"
        case .getMyAddress:
            return "user/getAddressList"
        
        case .getCommenInfo:
            return "user/getUserInfo"
        //积分信息
        case .getMyIntegralInfo:
            return "user/myIntegral"
        }
    }
    
    var method: Moya.Method {
        switch self {
        default:
            return .post
        }
    }
    

    //    这个是做单元测试模拟的数据，必须要实现，只在单元测试文件中有作用
    var sampleData: Data {
        return "".data(using: String.Encoding.utf8)!
    }

    //    该条请API求的方式,把参数之类的传进来
    var task: Task {
//        return .requestParameters(parameters: nil, encoding: JSONArrayEncoding.default)
        switch self {
        case .getCityCode:
            return .requestPlain
        case let .searchHotelList(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelDetail(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelAllMsg(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelImageList(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelRoomImage(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchRoomImagesV2(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelPrice(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .hotelAvail(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchTrainAndAirportByCityId(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchHotelCondition(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .searchSubwayInfomation(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .createHotelOrder(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .orderPay(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .getCityIdByName(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case let .getHotelCondition(parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getStationData:
            return .requestPlain
        case .searchTrainsBetweenStations(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getStopStations(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .apply12306Login(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .get12306LoginStatus(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .createOrder(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderCancel(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderRefund(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderChangeQuery(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .gitIdCardList:
            return .requestPlain
        case .addUserIdCard(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .updateUserIdCard(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .delUserIdCard(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .smsVerify12306Account(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getOrderList(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderChangePay(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .mobilelogin(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)

        case .getScenicSpotCondition:
            return .requestPlain
        case .getScenicSpotList(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getScenicSpotDetail(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getResourceDetail(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderDynamicTemplate(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getResourcePriceCalendar(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .orderCanBooking(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .tcreateOrder(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .torderPay(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .tgetOrderList(parameters: let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .tgetCityCode:
            return .requestPlain
        case .railwaysOrderPay(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getCommentList( let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .hoteevaluate( let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .serviceGetNews:
            return .requestPlain
        case .serviceGetNewsById( let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .addAirportTransfer(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .addRoadRescue( let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .addCarRental(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        case .getFlightOrderList(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .getRailwayOrderList(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .getHotelOrderList(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .getBonusOrder(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .feedBack(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .contactUS:
            return .requestParameters(parameters: ["": ""], encoding: URLEncoding.default)
        case .getMyAddress:
            return .requestParameters(parameters: ["": ""], encoding: URLEncoding.default)
        
        case .getMyOrder(let parameters):
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
            
        case .getCommenInfo:
            return .requestParameters(parameters: ["": ""], encoding: URLEncoding.default)
        
        default:
            return .requestParameters(parameters: ["": ""], encoding: URLEncoding.default)
        }

    }
 
    
    
    var headers: [String : String]? {
        let token = UserDefaults.standard.object(forKey: "token")
        
        if let token1 = token{

            return ["token":"\(token1)"]
        }
        return ["token":""]
    }
}
